<template>
  <div
    class="box"
    @click="
      $router.push({
        path: '/detail',
        query: {
          id: item.id,
        },
      })
    "
  >
    <div class="example">
      <img :src="item.pictureOriginal" alt="" />
      <div class="collect" v-if="token">
        <i
          class="el-icon-star-off"
          style="color: #ec6c15; margin-right: 0.04rem"
        ></i>
        <span v-if="item.collection">已收藏</span>
        <span @click="saveProductCollection" v-else>收藏</span>
      </div>
      <!-- <div class="collect1">
        <i class="el-icon-star-on" style="color: #EC6C15;margin-right: 0.04rem;"></i>
        <span>已收藏</span>
      </div> -->

      <div class="join">加入购物车</div>
      <div class="join join1">立即下单</div>
    </div>

    <div class="producemsg">
      <div class="item">{{ item.specification }}</div>
      <div class="item1">{{ item.goodsName }}</div>
      <div class="price">
        <div class="num">
          <span style="font-size: 0.14rem">¥</span>
          {{ item.price }}
        </div>
        <div class="sellnum">分销量：{{ item.salesPoints }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { saveProductCollection, saveStoreCollection } from "@/api/MyCollection";
import { getToken, removeToken } from "@/utils/auth";
export default {
  props: ["item"],
  components: {},

  data() {
    return {
      token: null,
    };
  },
  created() {},
  activated() {
    this.token = getToken();
  },
  methods: {
    //收藏商品
    saveProductCollection() {
      saveProductCollection({
        idList: `${this.item.id}`,
      }).then((data) => {
        if (data.code == 200) {
          this.$message({
            message: "收藏成功",
            type: "success",
          });
          item.collection = true;
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.box:hover {
  .example .join {
    display: block !important;
  }
}
.box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  .example {
    width: 2.18rem;
    height: 2.18rem;
    position: relative;
    img {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
    .collect {
      width: 0.64rem;
      height: 0.24rem;
      line-height: 0.24rem;
      text-align: center;
      border-radius: 0.2rem;
      color: #ec6c15;
      font-size: 0.12rem;
      position: absolute;
      top: 0.08rem;
      right: 0.08rem;
      background: #ffffff;
      cursor: pointer;
    }
    .collect1 {
      width: 0.64rem;
      height: 0.24rem;
      line-height: 0.24rem;
      text-align: center;
      color: #ec6c15;
      font-size: 0.12rem;
      position: absolute;
      top: 0.08rem;
      right: 0.08rem;
    }
    .join {
      width: 1.08rem;
      height: 0.32rem;
      line-height: 0.32rem;
      text-align: center;
      font-size: 0.12rem;
      color: #ffffff;
      position: absolute;
      left: 0;
      bottom: 0;
      background: #ec6c15;
      display: none;
      cursor: pointer;
    }
    .join1 {
      position: absolute;
      left: 1.1rem !important;
      bottom: 0 !important;
    }
  }
  .producemsg {
    padding: 0.09rem 0.06rem 0.15rem 0.06rem;
    width: calc(100% - 0.12rem);
    height: 0.68rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    .item {
      width: 100%;
      text-align: left;
      font-size: 0.12rem;
      color: #000000;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      white-space: nowrap;
    }
    .item1 {
      margin-top: 0.08rem;
      width: 90%;
      text-align: left;
      font-size: 0.12rem;
      color: #666666;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      white-space: nowrap;
    }
    .price {
      width: 100%;
      flex: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .num {
        font-size: 0.18rem;
        color: #e22a1f;
      }
      .sellnum {
        font-size: 0.12rem;
        color: #999999;
      }
    }
  }
}
</style>
